public class PredictTheWinner {

    public boolean PredictTheWinner(int[] nums) {
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
        }
        int first = f(nums, 0, nums.length - 1);
        return first >= (sum - first) ? true : false;
    }

    public int f(int[] nums, int l, int r) {
        if (l == r) return nums[l];
        return Math.max(nums[l] + s(nums, l + 1, r), nums[r] + s(nums, l, r - 1));
    }

    public int s(int[] nums, int l, int r) {
        if (l == r) return 0;
        return Math.min(f(nums, l + 1, r), f(nums, l, r - 1));
    }
}
